package com.gp.testonline.controller;
import com.gp.testonline.eo.ExamanswerEOPage;
import com.gp.testonline.model.Examanswer;
import com.gp.testonline.service.ExamanswerService;
import com.gp.testonline.tool.ResponseMessage;
import com.gp.testonline.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 对外提供数据服务接口
 */
@Api(tags = "examanswer")
@RestController
public class ExamanswerController {
    @Autowired
    private ExamanswerService examanswerService;

    @ApiOperation(value = "试卷答题信息添加方法")
    @RequestMapping(value = "/insertExamanswer",method = RequestMethod.GET)
    public ResponseMessage insert(Examanswer examanswer){
        int IsInsert=0;
        //传入数据的判断
        //(1) examanswer不能为空
        if (examanswer!=null){
            //(2) 编号不能为0
            if (examanswer.getEaid()!=0){
                //(3) 添加数据
                IsInsert=examanswerService.InsertExamanswer(examanswer);
                if (IsInsert==1){
                    return Result.success("添加成功！");
                }else if (IsInsert==-1){
                    return Result.error("添加失败！");
                }else{
                    return Result.error("保存失败！");
                }
            }
        }
        return Result.error("保存失败！");
    }

    @ApiOperation(value = "根据条件获取试卷答题详细信息")
    @RequestMapping(value = "/getExamanswer",produces = "application/json;charest=utf-8",method = RequestMethod.PUT)
    public ResponseMessage getExamanswer(ExamanswerEOPage examanswerEOPage) {
        Map<String, List> map = new HashMap<>();
        List<ExamanswerEOPage> listExamanswer = examanswerService.getExamanswerAll(examanswerEOPage);
        map.put("list",listExamanswer);
        return Result.success("200",map);
    }
}
